package com.googlecode.bip.xml.export;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
import javax.naming.NamingException;

/**
 * Handle XML export from MySQL database
 */
//not public
class XMLQuestionLocal implements XMLAppender
{
    private static final long serialVersionUID = 1L;
    private String idlocal;
    private String questionname;
    private String questiondescription;
    private List<XMLValueDescriptions> valuedescriptionsList;

    public XMLQuestionLocal(
            XMLSurveyConnection connection,
            String              local,
            String              questionname,
            String              questiondescription,
            XMLQuestion         xmlQuestion
            )
        throws SQLException, NamingException
    {
        this.idlocal = local;
        this.questionname = questionname;
        this.questiondescription = questiondescription;

        this.valuedescriptionsList = XMLValueDescriptionsFactory.createList( connection, xmlQuestion );
    }


    /**
     * <XMP>
     * <!ELEMENT questionlocal         (local,questionname,questiondescription,valuedescriptions*)>
     * <!ELEMENT questionname          (#PCDATA)>
     * <!ELEMENT questiondescription   (#PCDATA)>
     * </XMP>
     */
    @Override
    public void appendXML( Appendable a ) throws IOException
    {
        a.append( "<questionlocal>\n" );

        XMLAppenderHelper.appendXMLValue( a, "local", idlocal );
        XMLAppenderHelper.appendXMLValue( a, "questionname", questionname );
        XMLAppenderHelper.appendXMLValue( a, "questiondescription", questiondescription );

        XMLAppenderHelper.appendXML( a, valuedescriptionsList );

        a.append( "</questionlocal>\n" );
    }

}
